/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.inse6260.atms.model;

import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import javax.sql.rowset.JdbcRowSet;
import com.sun.rowset.JdbcRowSetImpl;   // Sun's JdbcRowSet implementation
import java.util.ArrayList;
import java.util.Date;
import java.sql.Timestamp;

/**
 *
 * @author dimitri.tiago
 */
public class Test
{
    static private JdbcRowSet rowSet;  // row set object to interact with database

    // JDBC driver name and database URL
    static final String JDBC_DRIVER = "com.intersys.jdbc.CacheDriver";
    static final String DATABASE_URL = "jdbc:Cache://localhost:60601/INSE6260";
    static final String USERNAME = "_SYSTEM";
    static final String PASSWORD = "bsobso";

    public static void main(String args[])
    {
        try
        {
            // load driver class
            Class.forName(JDBC_DRIVER);

            // initialize jdbcRowSet
            rowSet = new JdbcRowSetImpl();
            rowSet.setUrl(DATABASE_URL);
            rowSet.setUsername(USERNAME);
            rowSet.setPassword(PASSWORD);

            // insert new transaction line item row
            String sqlQuery = String.format("SELECT * FROM atms.TransactionLineItem");
            rowSet.setCommand(sqlQuery);
            rowSet.execute();

            //int nextTransLineItemId = rowSet.getInt("transactionId") + 1;
            java.util.Date today = new java.util.Date();
            java.sql.Timestamp currTimestamp = new Timestamp(today.getTime());

            // update daily transaction limit
            while (rowSet.next())
            {
                System.out.println(rowSet.getTimestamp("transactionDate"));
            }
        }
        catch (SQLException sqlException)
        {
            sqlException.printStackTrace();
            System.exit(1);
        }
        catch (ClassNotFoundException classNotFound)
        {
            classNotFound.printStackTrace();
            System.exit(1);
        }
    }

}
